home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / mac / SRI / General Interest / Programming / J / Examples / misc.js < prev    next >
Encoding:
Text File  |  1993-12-02  |  2.2 KB  |  88 lines  |  [TEXT/????]

  1.    NB. miscellaneous utilities
  2.    NB.
  3.    NB.  bx          indices of 1's in boolean
  4.    NB.  deb         delete extra blanks
  5.    NB.  diff        differences
  6.    NB.  expand      expand numeric argument
  7.    NB.  fi          fix rank 1
  8.    NB.  flatten     flatten display to matrix
  9.    NB.  ifempty     return 1 if empty
  10.    NB.  jl          justify left
  11.    NB.  jr          justify right
  12.    NB.  lindex      linear indices - indexing utility
  13.    NB.  nubcount    nub + count
  14.    NB.  pathname    split DOS name into path;name
  15.    NB.  ruler       ruler
  16.    NB.  show        show explicit definition
  17.    NB.  sort        sort
  18.    
  19.    t=. 'bx deb diff expand fi flatten'
  20.    t=. t,' ifempty jl jr lindex nubcount'
  21.    t=. t,' pathname ruler show sort'
  22.    SCRIPTNAMES=: t
  23.    
  24.    bx=:       # i. @ #
  25.    deb=:      '(b+.1|.b></\b=.y.~:'' '')#y.' :0
  26.    diff=:     2&(-~/\)
  27.    expand=:   (* +/\) @ [ { 0&,@]
  28.    fi=:       '0'&"."1
  29.    flatten=:  1 1&}. @ (_1 _1&}.)@ ": @ < 
  30.    ifempty=:  0&=&#&:>                                                
  31.    jl=:       (|.~ +/@(*./\)@(' '&=))"1
  32.    jr=:       (|.~ -@(+/)@(*./\.)@(' '&=))"1
  33.    c1=. +/"1@=
  34.    c2=. \:@c1 f.
  35.    nubcount=:   (c2 f. { ~.) ;"0 (c2 { c1) f.
  36.    pathname=: '(b#y.);(-.b=.+./\.y.=''\'')#y.' :0
  37.    sort=:     /:~
  38.    
  39.    NB. lindex
  40.    NB. e.g.  2 lindex 5 3$'a'
  41.    NB.       = 6 7 8   (indices of row 2)
  42.    lindex=:   [ { i.@$@]
  43.    
  44.    NB. ruler
  45.    NB. displays a ruler
  46.    NB. e.g.    ruler 75
  47.    NB.       1 ruler 30
  48.    ruler=: 0 : 0
  49. 0 ruler y.
  50. :     
  51.      j=. >. 0.2*len=. y.
  52.      $.=. >x.{L0;L1
  53.  
  54. L0)  r=. len #"1 ,. 193 32 194{a.
  55.      i=. }. 5*i.j
  56.      r=. (197{a.) (,(0,+:len)+/0,i) } r
  57.      r=. ('0',3 ": i) (len,,len+i-/2 1 0) } r
  58.      r [ $.=. i.0
  59.  
  60. L1)  r=. len # ,: 197 32 32 197{a.
  61.      i=. 0,}. 5*i.j
  62.      r=. (197{a.) (,0 3 +/ i*4) } r
  63.      r=. (,2 ": 100|i) (,(i*4) +/ 1 2) } r
  64. )
  65.    
  66.    NB. show
  67.    NB. e.g. show 'ruler'
  68.    show=: 0 : 0
  69. 1 1 show y.
  70. :
  71. NB. show explicit definition of verb
  72. NB. x.= (1=line nos), (1=frame)
  73. x.=. 2{.x.
  74. $.=. (y.-:>y.)}.$.
  75. ,.(<x.)$:&.>y. [ $.=. ''
  76. 'ajc'=. ,.&.>5!:2<y.
  77. y.=. ':',~y.-.' '
  78. $.=. ,>(0{x.){L0;$.
  79. r=. (#a)>.#c
  80. b=. ' '={."1 r=. ":,.i.r
  81. r=. '[',"1 b|."0 1 r,"1'] '
  82. a=. ((#a){.r),"1 a
  83. c=. ((#c){.r),"1 c
  84. L0)$.=. {.(-. 1{x.)}.$.
  85. ,.y.;a;c
  86. y.,a,(-.0 e. $c)#(,'≡≡≡'),c
  87. )
  88.